import { combineReducers, ActionCreatorWithPayload, createAction } from '@reduxjs/toolkit';
import { createTempSlice } from '@/stores/createTempSlice';
import { TAB_DEFAULT_KEY } from '@/pages/ranking/constants';
interface IRankingAction {
  setTabKey: ActionCreatorWithPayload<string, string>;
}
export const rankingActions: IRankingAction = {
  setTabKey: createAction('INIT'),
};
// 导出一个函数createReducer，用于创建一个reducer
export const createReducer = (key: string) => {
  // 使用createTempSlice函数创建一个临时slice，用于存储activeTabkey的值，默认值为TAB_DEFAULT_KEY，key为传入的参数
  const { set: setTabKey, reducer: activeTabkey } = createTempSlice<string>('activeTabkey', TAB_DEFAULT_KEY, key);
  // 将setTabKey赋值给rankingActions的setTabKey属性
  rankingActions.setTabKey = setTabKey;
  // 返回一个对象，包含reducer属性，reducer属性为一个combineReducers函数，用于将activeTabkey合并为一个reducer
  return {
    reducers: {
      [key]: combineReducers({
        activeTabkey,
      }),
    },
  };
};
